#!/bin/ash

IFS=""

if [ $1 == "9341" ]; then
	rm -f /tmp/stainfo
	online_num=`iw dev wlan0 station dump |grep Station|wc -l`
	res=`iw dev wlan0 station dump`
	i=1
	if [ ${#res} != 0 ]; then
		while [ $i -le $online_num ]
		do
			sta_mac=$(echo $res |grep "Station"|awk -F " " '{print $2}'|awk NR==$i)
			sta_sgi=$(echo $res |grep "signal:"|awk -F " " '{print $4}'|awk NR==$i|cut -c 1-3)      #SGI
			sta_mimo=$(echo $res |grep "signal avg"|awk -F " " '{print $4}'|awk NR==$i|cut -c 2-4)  #MIMOPS
			sta_mcs=$(echo $res |grep "tx bitrate"|awk -F ' ' '{print $3}'|awk NR==$i|cut -c 1) #MCS
			sta_bw=$(echo $res |grep "tx retries"|awk -F " " '{print $3}'|awk NR==$i|cut -c 1-2)                 #BW
			sta_stbc=$(echo $res |grep "failed:"|awk -F " " '{print $3}'|awk NR==$i)                #STBC
		        echo $sta_mac$'\t'$i$'\t'$sta_mimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi >> /tmp/stainfo
		#	echo $sta_mac$'\t'$i$'\t'$sta_iimimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi$'\t'$sta_stbc >> /tmp/stainfo
		
			i=$(($i+1))
		done
	fi
elif [ $1 == "9557_DEF" ]; then
	rm -f /tmp/stainfo
	res=`iw dev wlan0 station dump`
	online_num=`iw dev wlan0 station dump |grep Station|wc -l`
	i=1
	if [ ${#res} != 0 ]; then
		while [ $i -le $online_num ]
		do
			sta_mac=$(echo $res |grep "Station"|awk -F " " '{print $2}'|awk NR==$i)
			sta_sgi=$(echo $res |grep "signal:"|awk -F " " '{print $4}'|awk NR==$i|cut -c 1-3)      #SGI
			sta_mimo=$(echo $res |grep "signal avg"|awk -F " " '{print $4}'|awk NR==$i|cut -c 2-4)  #MIMOPS
			sta_mcs=$(echo $res |grep "tx bitrate"|awk -F ' ' '{print $3}'|awk NR==$i|cut -c 1) #MCS
			sta_bw=$(echo $res |grep "tx retries"|awk -F " " '{print $3}'|awk NR==$i|cut -c 1-2)                 #BW
			sta_stbc=$(echo $res |grep "failed:"|awk -F " " '{print $3}'|awk NR==$i)                #STBC
		        echo $sta_mac$'\t'$i$'\t'$sta_mimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi >> /tmp/stainfo
		#	echo $sta_mac$'\t'$i$'\t'$sta_iimimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi$'\t'$sta_stbc >> /tmp/stainfo
			i=$(($i+1))
		done
	fi
	res=`iw dev wlan1 station dump`
	online_num=`iw dev wlan1 station dump |grep Station|wc -l`
	i=1
	if [ ${#res} != 0 ]; then
		while [ $i -le $online_num ]
		do
			sta_mac=$(echo $res |grep "Station"|awk -F " " '{print $2}'|awk NR==$i)
			sta_sgi=$(echo $res |grep "signal:"|awk -F " " '{print $4}'|awk NR==$i|cut -c 1-3)      #SGI
			sta_mimo=$(echo $res |grep "signal avg"|awk -F " " '{print $4}'|awk NR==$i|cut -c 2-4)  #MIMOPS
			sta_mcs=$(echo $res |grep "tx bitrate"|awk -F ' ' '{print $3}'|awk NR==$i|cut -c 1) #MCS
			sta_bw=$(echo $res |grep "tx retries"|awk -F " " '{print $3}'|awk NR==$i|cut -c 1-2)                 #BW
			sta_stbc=$(echo $res |grep "failed:"|awk -F " " '{print $3}'|awk NR==$i)                #STBC
		        echo $sta_mac$'\t'$i$'\t'$sta_mimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi >> /tmp/stainfo
		#	echo $sta_mac$'\t'$i$'\t'$sta_iimimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi$'\t'$sta_stbc >> /tmp/stainfo
			i=$(($i+1))
		done
	fi
elif [ $1 == "9557" ]; then
	rm -f /tmp/stainfo
	res=`wlanconfig ath0 list sta |grep -v "ADDR"`
	online_num=`wlanconfig ath0 list sta |grep -v "ADDR"|wc -l`
	i=1
	if [ ${#res} != 0 ]; then
		while [ $i -le $online_num ]
		do
			sta_mac=$(echo $res |awk -F " " '{print $1}'|awk NR==$i)
			sta_sgi=$(echo $res |awk -F " " '{print $2}'|awk NR==$i)
			sta_mimo=$(echo $res |awk -F " " '{print $3}'|cut -c1-2|awk NR==$i)
			sta_bw=$(echo $res |awk -F " " '{print $5}'|awk NR==$i)
			sta_mcs=$(echo $res |awk -F " " '{print $6}'|awk NR==$i)
			echo $sta_mac$'\t'$i$'\t'$sta_mimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi >> /tmp/stainfo
			i=$(($i+1))
		done
	fi
	res=`wlanconfig ath1 list sta |grep -v "ADDR"`
	online_num=`wlanconfig ath1 list sta |grep -v "ADDR"|wc -l`
	i=1
	if [ ${#res} != 0 ]; then
		while [ $i -le $online_num ]
		do
			sta_mac=$(echo $res |awk -F " " '{print $1}'|awk NR==$i)
			sta_sgi=$(echo $res |awk -F " " '{print $2}'|awk NR==$i)
			sta_mimo=$(echo $res |awk -F " " '{print $3}'|cut -c1-2|awk NR==$i)
			sta_bw=$(echo $res |awk -F " " '{print $5}'|awk NR==$i)
			sta_mcs=$(echo $res |awk -F " " '{print $6}'|awk NR==$i)
			echo $sta_mac$'\t'$i$'\t'$sta_mimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi >> /tmp/stainfo
			i=$(($i+1))
		done
	fi

elif [ $1 == "7620" ]; then
	rm -f /tmp/stainfo
	online_num=`iwinfo ra0 assoclist |grep SNR|wc -l`
	sta_mimo=`iwinfo ra0 assoclist|grep SNR|awk -F ' ' '{print $5}'|cut -c3|awk NR==1`"0"
	sta_mcs=`iwinfo ra0 assoclist |grep MCS|awk -F ' ' '{print $5}'|cut -c 1|awk NR==1`
	sta_bw=`iwinfo ra0 assoclist |grep MCS|awk -F ' ' '{print $2}'|cut -c 1|awk NR==1`
	sta_stbc=$sta_bw
	res=`iwinfo ra0 assoclist |grep SNR`
	i=1
	if [ ${#res} != 0 ]; then
		while [ $i -le $online_num ]
		do
			sta_mac=$(echo $res |awk -F " " '{print $1}'|awk NR==$i)
			sta_sgi=$(echo $res |awk -F " " '{print $2}'|awk NR==$i)      #SGI
			echo $sta_mac$'\t'$i$'\t'$sta_mimo$'\t'$sta_mcs$'\t'$sta_bw$'\t'$sta_sgi >> /tmp/stainfo
			i=$(($i+1))
		done
	fi
fi
